import { defineSource } from '../source';
import { ProcessedItem } from '../types'
import { myFetch } from "../utils/fetch"
import logger from '../../framework/config/logger';

interface Res {
    list: {
        data: {
            id: string
            title: string
            // 北京时间
            url: string
            publishTime: string
        }
    }[]
}

/**
 * 排行榜 
 */
export default defineSource({
    cankaoxiaoxi: async (): Promise<ProcessedItem[]> => {
        const res = await Promise.all(["zhongguo", "guandian", "gj"].map(k => myFetch(`https://china.cankaoxiaoxi.com/json/channel/${k}/list.json`) as Promise<Res>))
        return res.map(k => k.list).flat().map(k => ({
            id: k.data.id,
            title: k.data.title,
            url: k.data.url,
            date: k.data.publishTime,
        })).sort((m, n) => m.date < n.date ? 1 : -1)
    }
});
